package com.dong.stack;

import java.util.Deque;
import java.util.LinkedList;

public class Demo4 {
    public static void main(String[] args) {
        String s = "abbaca";
        System.out.println(removeDuplicates(s));
    }

    public static String removeDuplicates(String s) {
        Deque<Character> deque = new LinkedList<>();
        int len = s.length();
        char target;
        for (int i = 0; i < len; i++) {
            target = s.charAt(i);
            if (deque.isEmpty() || deque.peek()!= target){
                deque.push(target);
            }
            else {
                deque.pop();
            }
        }

        String str = "";
        while (!deque.isEmpty()){
            str = deque.pop()+
                    str;
        }
        return str;


    }

}
